import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LoginView from '../views/LoginView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/main',
      name: 'main',
      component: HomeView,
      meta: { requiresAuth: true },
      children: [
        {
          path: 'workbench',
          name: 'workbench',
          component: () => import('../views/WorkbenchView.vue'),
          meta: { title: '工作台' }
        },
        {
          path: 'ai-customer-service',
          name: 'ai-customer-service',
          component: () => import('../views/AiCustomerService.vue'),
          meta: { title: 'AI智能客服' }
        },
        {
          path: 'procurement/purchase-order',
          name: 'purchase-order-main',
          component: () => import('../views/purchase-order/PurchaseOrderMain.vue'),
          meta: { title: '采购订单' }
        },
        {
          path: 'procurement/purchase-order/create',
          name: 'purchase-order-create',
          component: () => import('../views/purchase-order/PurchaseOrderForm.vue'),
          meta: { title: '新增采购订单' }
        },
        {
          path: 'procurement/purchase-order/:id/edit',
          name: 'purchase-order-edit',
          component: () => import('../views/purchase-order/PurchaseOrderForm.vue'),
          meta: { title: '编辑采购订单' }
        },
        {
          path: 'procurement/purchase-order/:id',
          name: 'purchase-order-detail',
          component: () => import('../views/purchase-order/PurchaseOrderDetail.vue'),
          meta: { title: '采购订单详情' }
        },
        {
          path: 'enhanced-weather',
          name: 'enhanced-weather',
          component: () => import('../views/EnhancedWeather.vue'),
          meta: { title: '天气预报' }
        },
        {
          path: 'device-monitoring',
          name: 'device-monitoring',
          component: () => import('../views/DeviceMonitoring.vue'),
          meta: { title: '设备监控大屏' }
        }
      ]
    },
    {
      path: '/home',
      redirect: '/main/workbench'
    },

    {
      path: '/',
      name: 'login',
      component: LoginView,
      meta: { requiresAuth: false }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
      meta: { requiresAuth: true }
    }
  ],
})

export default router
